//
//  MSImageView.swift
//  onemeetingmac
//
//  Created by 张衡 on 2020/6/10.
//  Copyright © 2020 onemeeting. All rights reserved.
//

import Foundation

class MSImageView: NSImageView {
    
    var tap:OneViewBlock?
    var status:OneStatusBlock?
    
    var _tag:Int = 0
    override var tag: Int {
        get {
            return _tag
        }
        set(tag){
            _tag = tag
        }
    }
    
    override func draw(_ dirtyRect: NSRect) {
        
        super.draw(dirtyRect)
           
        let optios:NSTrackingArea.Options = [
            NSTrackingArea.Options.mouseEnteredAndExited,
            NSTrackingArea.Options.mouseMoved,
            NSTrackingArea.Options.cursorUpdate,
            NSTrackingArea.Options.activeWhenFirstResponder,
            NSTrackingArea.Options.activeInKeyWindow,
            NSTrackingArea.Options.activeInActiveApp,
            NSTrackingArea.Options.activeAlways,
            NSTrackingArea.Options.assumeInside,
            NSTrackingArea.Options.inVisibleRect,
            NSTrackingArea.Options.enabledDuringMouseDrag
        ]
           
        let area = NSTrackingArea.init(rect: dirtyRect, options: optios, owner: self, userInfo: nil)
        self.addTrackingArea(area)
        self.becomeFirstResponder()
    }
    
    
    override func mouseDown(with event: NSEvent) {
        super.mouseDown(with: event)
        if self.tap != nil {
            self.tap!(self)
        }
        if status != nil {
            self.status!(.selected)
        }
    }
    
    override func mouseUp(with event: NSEvent) {
        super.mouseEntered(with: event)
        if status != nil {
            self.status!(.highlight)
        }
        
    }
    
    override func mouseEntered(with event: NSEvent) {
        super.mouseEntered(with: event)
        if status != nil {
            self.status!(.hover)
        }
    }
    
    override func mouseExited(with event: NSEvent) {
        super.mouseExited(with: event)
        if status != nil {
            self.status!(.normal)
        }
    }
}
